home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- #
- # File ShowTasks.c
- #
- # an A/ROSE programming exercise
- #
- # MPW build commands:
- #
- C ShowTasks.c
- Link -w -c 'MPS ' -t MPST ∂
- ShowTasks.c.o ∂
- "{CLibraries}"CSANELib.o ∂
- "{CLibraries}"Math.o ∂
- "{CLibraries}"StdClib.o ∂
- "{CLibraries}"CInterface.o ∂
- "{Libraries}"Stubs.o ∂
- "{CLibraries}"CRuntime.o ∂
- "{Libraries}"Interface.o ∂
- "{Libraries}"ToolLibs.o ∂
- "{AROSEPrep}"IPCGlue.o ∂
- -o ShowTasks
- #
- ------------------------------------------------------------------------------*/
-
- #include <Types.h>
- #include <Memory.h>
- #include <Packages.h>
- #include <Stdlib.h>
- #include <StdIO.h>
- #include <Slots.h>
- #include <String.h>
- #include <Strings.h>
-
- //--- included from "os.h" :
-
- typedef long tid_type;
-
- struct mMessage
- {
- struct mMessage *mNext;
- long mId;
- short mCode;
- short mStatus;
- unsigned short mPriority;
- tid_type mFrom;
- tid_type mTo;
- unsigned long mSData [3];
- unsigned long mOData [3];
- long mDataSize; // Size of data buffer in bytes. set to negative
- // size of buffer if buffer is shared
- // between tasks. eg. Buffer cannot be copied
- char *mDataPtr;
- };
-
- typedef struct mMessage mMessage;
-
-
- #define OS_MATCH_ALL 0 // on receive match anything
- #define OS_NO_TIMEOUT 0 // receive waits forever for message
-
-
- //--- included from "managers.h" :
-
-
- #define NM_LOOKUP_NAME 104 // message code for "lookup name"
-
- // the following is a cosmetic variant of the original definition
-
- typedef unsigned char Str33[34];
-
- struct ra_lnm // return area for lookup name
- {
- Str33 ra_on; // object name
- Str33 ra_tn; // type name
- };
- typedef struct ra_lnm ra_lnm;
-
-
- struct pb_lookup_name
- {
- tid_type lnm_tid; // process id
- unsigned short lnm_index; // index (INPUT/OUTPUT)
- unsigned short lnm_RAsize; // size of return area
- ra_lnm lnm_ra [1]; // return area (OUTPUT)
- };
- typedef struct pb_lookup_name pb_lookup_name;
-
-
- #define ICC_GETCARDS 150
- // Get list of active cards and their name manager addresses.
- // mDataPtr points to an array of 16 longwords (indexed by slots)
- // On return, and entry < 0 means card not present,
- // = 0 means card present - no name manager,
- // > 0 means TID of name manager on card
- // may be used in mTo field of a message
-
-
- // prototypes:
-
- void main();
- Boolean AskICCM();
- void namelookup(tid_type ntid, tid_type tid);
- void NumToHex( long n, short d, char *s);
-
- extern void FreeMsg();
- extern mMessage *GetMsg(void);
- extern mMessage *Receive();
- extern void Send(mMessage *);
-
- extern tid_type GetTID(void);
- extern tid_type GetICCTID(void);
- extern tid_type Lookup_Task(char *, char *, tid_type, unsigned short *);
-
- extern tid_type OpenQueue();
- extern void CloseQueue();
-
- static tid_type cards[16];
-
- void main()
- {
- short slot;
- tid_type tid;
- unsigned short index;
-
- if (! OpenQueue(0)) {
- printf("### (OpenQueue fails) \n");
- return;
- }
-
- if (! AskICCM()) {
- printf("### (AskICCM fails) \n");
- return;
- }
-
- for (slot=0; slot<15; slot++) {
- if (cards[slot] > 0)
- {
- printf("\nslot = $%X :\n",slot);
- index = 0;
- while ((tid = Lookup_Task ("=", "=", cards[slot], &index)))
- namelookup(cards[slot], tid);
- }
- }
-
- CloseQueue ();
-
- } // main()
-
-
-
- Boolean AskICCM()
- {
- Boolean result;
- mMessage *m;
-
-
- if (GetICCTID() != 0)
- {
- if ((m = GetMsg ()) == 0) {
- printf("### (GetMsg fails) \n");
- return(false);
- }
-
- m -> mTo = GetICCTID ();
- m -> mCode = ICC_GETCARDS;
- m -> mDataPtr = (char *) cards;
- m -> mDataSize = sizeof (tid_type) * 16;
- Send (m);
- m = Receive (OS_MATCH_ALL, OS_MATCH_ALL, ICC_GETCARDS+1, OS_NO_TIMEOUT, 0);
- result = (m -> mStatus == 0); // slotInfo is in cards[0..15] !
- FreeMsg(m);
- return(result);
- }
- else
- return(false);
-
- } // AskICCM()
-
-
- #define bufferSize 512
-
- void namelookup(tid_type ntid, tid_type tid)
- {
- pb_lookup_name *lnam_ptr;
- char buffer[bufferSize];
- char sn[33];
- mMessage *m;
-
- if ((m = GetMsg ()) == 0) {
- printf("### (GetMsg fails) \n");
- return;
- }
- m -> mTo = ntid;
- m -> mCode = NM_LOOKUP_NAME;
- m -> mDataPtr = buffer;
- m -> mDataSize = bufferSize;
-
- lnam_ptr = (pb_lookup_name *) &buffer;
- lnam_ptr -> lnm_index = 0;
- lnam_ptr -> lnm_tid = tid;
- lnam_ptr -> lnm_RAsize = bufferSize - (sizeof(pb_lookup_name) - sizeof(ra_lnm));
-
- Send (m);
- m = Receive (OS_MATCH_ALL, OS_MATCH_ALL, NM_LOOKUP_NAME+1, OS_NO_TIMEOUT, 0);
-
- if (m -> mStatus == 0) {
- NumToHex(tid, 8, sn);
- printf("$%s: name \"",sn+1);
- strcpy(sn, ((pb_lookup_name *)(m -> mDataPtr)) -> lnm_ra[0].ra_on);
- p2cstr(sn);
- printf("%s", sn);
- printf("\", type \"");
- strcpy(sn, ((pb_lookup_name *)(m -> mDataPtr)) -> lnm_ra[0].ra_tn);
- p2cstr(sn);
- printf("%s", sn);
- printf("\"\n");
- }
- else
- printf("Receive in NameLookup failed\n\n");
-
- FreeMsg(m);
-
- } // namelookup()
-
-
-
- void NumToHex( long n, short d, char *s) // I hate this @#%@ !
- // s must point to at least d+1 free bytes - returns 0-terminated Pascal String of length d
- // requires d > 0
- {
- short c;
-
- s[0] = d;
- s[d+1] = 0x0;
- do {
- c = (n & 0x0F) + 48;
- if (c>57)
- c = c+7;
- s[d--] = (char) c;
- n = n>>4;
- } while (d > 0);
- } // NumToHex()